//
//  SDHSportsLiveHeaderView.m
//  SDHSportsNews
//
//  Created by MichaelShan on 2021/3/13.
//

#import "SDHSportsLiveHeaderView.h"
#import "SDHSportsMatchSoccerModel.h"
#import "UIImageView+YQAdd.h"

@interface SDHSportsLiveHeaderView ()

@property (nonatomic, strong) UIImageView *leftImgView;
@property (nonatomic, strong) UILabel *leftNameLb;
@property (nonatomic, strong) UILabel *leftScoreLb;
@property (nonatomic, strong) UIImageView *rightImgView;
@property (nonatomic, strong) UILabel *rightNameLb;
@property (nonatomic, strong) UILabel *rightScoreLb;


@end

@implementation SDHSportsLiveHeaderView

- (id)init {
    if (self = [super init]) {
        [self initUI];
    }
    
    return self;
}

- (void)initUI {
    UIView *leftView = [UIView new];
    leftView.backgroundColor = UIColorFromRGB(255, 129, 69);
    [self addSubview:leftView];
    
    UIImageView *leftImgView = [UIImageView new];
    leftImgView.clipsToBounds = YES;
    leftImgView.layer.cornerRadius = 25;
    leftImgView.image = [UIImage imageNamed:@"touxiang"];
    [leftView addSubview:leftImgView];
    self.leftImgView = leftImgView;
    
    UILabel *leftNameLb = [UILabel new];
    leftNameLb.textAlignment = NSTextAlignmentLeft;
    leftNameLb.textColor = [UIColor whiteColor];
    leftNameLb.font = [UIFont boldSystemFontOfSize:16];
    leftNameLb.numberOfLines = 0;
    [leftView addSubview:leftNameLb];
    self.leftNameLb = leftNameLb;
    leftNameLb.text = @"Antalya Sports";
    
    UILabel *leftScore = [UILabel new];
    leftScore.textAlignment = NSTextAlignmentCenter;
    leftScore.textColor = [UIColor whiteColor];
    leftScore.font = [UIFont boldSystemFontOfSize:18];
    leftScore.backgroundColor = [UIColor blackColor];
    [leftView addSubview:leftScore];
    self.leftScoreLb = leftScore;
    leftScore.text = @"3";
    
    [leftView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.mas_equalTo(0);
        make.width.mas_equalTo(kScreenWidth/2-3);
        make.height.mas_equalTo(kScoreHeaderHeight);
    }];
    
    [leftImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(15);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(50);
    }];
    
    [leftNameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(leftImgView);
        make.top.equalTo(leftImgView.mas_bottom).offset(10);
//        make.right.equalTo(leftImgView).offset(50);
    }];
    
    [leftScore mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-30);
        make.centerY.mas_equalTo(0);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(24);
    }];
    
    UIView *rightView = [UIView new];
    rightView.backgroundColor = UIColorFromRGB(121, 78, 205);
    [self addSubview:rightView];
    
    UIImageView *rightImgView = [UIImageView new];
    rightImgView.image = [UIImage imageNamed:@"touxiang"];
    rightImgView.clipsToBounds = YES;
    rightImgView.layer.cornerRadius = 25;
    [rightView addSubview:rightImgView];
    self.rightImgView = rightImgView;
    
    UILabel *rightNameLb = [UILabel new];
    rightNameLb.textAlignment = NSTextAlignmentRight;
    rightNameLb.textColor = [UIColor whiteColor];
    rightNameLb.font = [UIFont boldSystemFontOfSize:16];
    [rightView addSubview:rightNameLb];
    self.rightNameLb = rightNameLb;
    rightNameLb.text = @"Karagurak";
    
    UILabel *rightScore = [UILabel new];
    rightScore.textAlignment = NSTextAlignmentCenter;
    rightScore.textColor = [UIColor whiteColor];
    rightScore.font = [UIFont boldSystemFontOfSize:18];
    rightScore.backgroundColor = [UIColor blackColor];
    [rightView addSubview:rightScore];
    self.rightScoreLb = rightScore;
    rightScore.text = @"1";
    
    [rightView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(0);
        make.top.mas_equalTo(0);
        make.width.mas_equalTo(kScreenWidth/2-3);
        make.height.mas_equalTo(kScoreHeaderHeight);
    }];
    
    [rightImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-20);
        make.top.mas_equalTo(15);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(50);
    }];
    
    [rightNameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(rightImgView);
        make.top.equalTo(rightImgView.mas_bottom).offset(10);
    }];
    
    [rightScore mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30);
        make.centerY.mas_equalTo(0);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(24);
    }];
}

- (void)updateContent:(SDHSportsMatchSoccerModel *)model {
    [self.leftImgView setImageWithURL:[NSURL URLWithString:model.guestTeamLogo] placeholderImage:[UIImage imageNamed:@"touxiang"]];
    [self.rightImgView setImageWithURL:[NSURL URLWithString:model.hostTeamLogo] placeholderImage:[UIImage imageNamed:@"touxiang"]];
    
    self.leftNameLb.text = model.guestTeamEnName;
    self.rightNameLb.text = model.hostTeamEnName;
    
    NSArray *scoreArr = [model.gameScore componentsSeparatedByString:@":"];
    self.leftScoreLb.text = [scoreArr firstObject];
    self.rightScoreLb.text = [scoreArr lastObject];
}

@end
